package com.baidu.videoseries.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ImageView;

import com.baidu.videoseries.util.MetricsUtils;

/**
 * Created by Kvin on 2016/12/28.
 */
public class HorImageView extends ImageView {
     private DisplayMetrics metrics;

    public HorImageView(Context context) {
        super(context);
    }

    public HorImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        metrics= MetricsUtils.winMetrics(context);
    }

    public HorImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public HorImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.rotate(90,metrics.widthPixels/2,metrics.heightPixels/2);
        super.onDraw(canvas);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
    }
}
